define([
    'zepto',
    'underscore',
    'backbone',
    "text!templates/client/pay.html",
    "wTools",
    "area",
    "validate"

], function ($, _, Backbone, template) {
    return Backbone.View.extend({
        $el: $main,
        el: $main0,
        template: _.template(template),
        events: {
            "tap #btn": "btn"
        },
        initialize: function () {
            $("#head_back").hide();
            var postData = {
                "content": wData.urlData.content
            }, that = this;

            wAjaxForm("getMerchantInfo", "", postData, function (result) {
                if (result.success) {
                    wData.childName = result.data.childName;
                    wData.QPAY=result.data.QPAY;
                    wData.WXPay=result.data.WXPay;
                    wData.urlData=result.data;
                    that.render(wData);
                }else{
                    wTips("请重试");
                }
            });
        },
        back: function () {
            history.back();
        },
        render: function (data) {
            var html = this.template(data);
            this.$el.html(html);
        },
        btn: function () {
            if ($("#amount").val() != "") {

                if (wIsWeixin()) {
                    //微信中,直接走微信渠道
                    if (wData.WXPay && wData.WXPay == "true") {
                        var postData = {
                            "amount": $("#amount").val(),
                            "partnerId": wData.urlData.partnerId,
                            "childId": wData.urlData.childId
                        };
                        wAjaxForm("wxPay", "", postData, function (result) {
                            if (result.success) {
                                location.href = result.data.codeUrl;
                            }
                        });
                    } else {
                        wTips("尚未开通微信支付权限");
                    }
                } else {
                    //非微信浏览器,走畅捷支付渠道
                    if (wData.QPAY && wData.QPAY == "true") {
                        $("#formAmount").val($("#amount").val());
                        $("#formChanjet").attr("action", App.severUrl + App.urlList["recvOrder"]).submit();
                        wLoading.start();
                    } else {
                        wTips("尚未开通畅捷支付权限");
                    }
                }
            } else {
                wTips("请输入金额");
            }
        },

        destroy: function () {
            this.undelegateEvents();
            this.$el.html("");
            delete this;
        }
    });
});